package com.foreverwin.mes.lims.comsumer;

import com.alibaba.fastjson.JSONObject;
import com.foreverwin.mes.lims.controller.LotTankController;
import com.foreverwin.mes.lims.service.ItemTankService;
import com.foreverwin.mes.lims.service.LotTankService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class TankComsumer {
    private final Logger logger = LoggerFactory.getLogger(LotTankController.class);

    @Autowired
    private LotTankService lotTankService;
    @Autowired
    private ItemTankService itemTankService;
    @JmsListener(destination = "LOT_IN_OR_OUT_TANK")
    public void lotInOrOutTank( String text ) {
        logger.info( "<<<<<<=======消息队列[LOT_IN_OR_OUT_TANK]，接收到信息!");
        try {
            JSONObject obj = JSONObject.parseObject(text);
            String site = obj.getString("SITE");
            String tank = obj.getString( "TANK" );
            String lot = obj.getString( "LOT" );
            String qty = obj.getString( "QTY" );
            String item = obj.getString( "ITEM" );
            String moveType = obj.getString( "MOVE_TYPE" );
            Date actionTime = obj.getDate( "ACTION_TIME");
            lotTankService.lotCheckinOrCheckOut(site,tank,lot,qty,item,moveType,actionTime);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @JmsListener(destination = "TANK_HIGH_OR_LOW")
    public void tankHighOrLow( String text ) {
        logger.info( "<<<<<<=======消息队列[TANK_HIGH_OR_LOW]，接收到信息!");
        try {
            JSONObject obj = JSONObject.parseObject(text);
            String site = obj.getString("SITE");
            String tank = obj.getString( "TANK" );
            String item = obj.getString( "ITEM" );
            String highOrLow = obj.getString( "HIGH_OR_LOW" );
            Date actionTime = obj.getDate( "ACTION_TIME");
            itemTankService.tankHighOrLow( site,tank,item,highOrLow,actionTime);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
